<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
	<title>收货地址</title>
	<link rel="stylesheet" type="text/css" href="https://at.alicdn.com/t/font_474420_d5fpk6an8w7b9.css">
	<link rel="stylesheet" type="text/css" href="css/swiper.min.css">
	<link rel="stylesheet" type="text/css" href="css/mui.css">
	<link rel="stylesheet" type="text/css" href="css/style.css">
	<script type="text/javascript" src="js/mui.min.js"></script>
	<script type="text/javascript" src="js/fontSize.js"></script>
	<script type="text/javascript" src="js/layer/layer.js"></script>
	<script type="text/javascript" src="js/zepto.min.js"></script>
	<script type="text/javascript" src="js/swiper.min.js"></script>
	<script type="text/javascript" src="js/vue.js"></script>
	<script type="text/javascript" src="js/jweixin-1.2.0.js"></script>
	<script type="text/javascript" src="js/config.js"></script>
</head>
<body class="paddingBottom">
<div id="app">
	<div class="emptyAdress" v-if="list.length==0">
		暂时没有收货地址哟~
	</div>
	<div class="pay_title borderBottom" v-for="item in list" @click="confirmAdress(item.id)">
		<ul>
			<li><span>{{item.name}}</span><span>{{item.mobile}}</span></li>
		   <li>{{item.distict}}{{item.street}}{{item.detail}}</li>
		</ul>
		<!-- <i class="iconfont icon-xiangyou"></i> -->
		<i class="iconfont icon-shanchu" @click.stop="conFirmDel(item.id)"></i>
		<i class="iconfont icon-bianji"  @click.stop="goDetail(item.id)"></i>
		<!-- <img src="img/p_92.png" alt=""> -->
	</div>
	<!-- <div class="pay_title">
		<ul>
			<li><span>王晓晓</span>  <span>153****8856</span></li>
		   <li>重庆市南岸区海棠溪街道重庆交通大学雅园A栋7</li>
		</ul>
		<i class="iconfont icon-xiangyou"></i>
		<i class="iconfont icon-shanchu"></i>
		<img src="img/p_92.png" alt="">
	</div> -->
	<div id="add_new_adress" @click="goNext">
		新增地址
	</div>
</div>
<script type="text/javascript">
	 var app = new Vue({
			el: '#app',
			data: {
			    list:[],
		        unionid:GetQueryString("unionid"),
		        token:GetQueryString("token"),
		        shopId:GetQueryString("shopId")?GetQueryString("shopId"):null,
		        flag:false
		       
			},
			mounted(){
			  this.getList();
			},
			methods:{
				getList(){
					var that=this;
					ajaxFun("GET","/trade/address/list",{
	                       token:this.token,
	                       // id:this.token 

	                    },function(data){
	                    	if(data.error==0){
                              that.list=data.addresses;
	                    	}else{

	                    	}
	                     
                    }); 
				},
				conFirmDel(id){
					var that=this;

					var btnArray = ['否', '是'];
	                mui.confirm('您确定要删除该地址吗？', '提示', btnArray, function(e) {
	                    if (e.index == 1) {
	                       that.delAddress(id);
	                    } else {
	                        // info.innerText = 'MUI没有得到你的认可，继续加油'
	                    }
	                });
				},
				delAddress(id){
  					var that=this;
					ajaxFun("GET","/trade/address/remove",{
	                       token:this.token,
	                       id:id
	                    },function(data){
	                    	if(data.error==0){
	                    		if(localStorage.id==id){
	                    			localStorage.id=null;
	                    		}
                                showLayer("删除成功");
                                that.getList();
	                    	}else{

	                    	}
	                     
                    });
				},
				confirmAdress(id){
					var that=this;
                   if(this.shopId){
                     	console.log(id)
                      localStorage.id=id;
                      setTimeout(function(){
                           window.location.replace("choice.html?token="+that.token+"&unionid="+that.unionid+"&shopId="+that.shopId);


                      },200);

                   }
				},
				goDetail(id){
					if(this.shopId){
						window.location.replace("add_address.html?token="+this.token+"&unionid="+this.unionid+"&id="+id+"&shopId="+this.shopId);
					}else{
						window.location.replace("add_address.html?token="+this.token+"&unionid="+this.unionid+"&id="+id);

					}
				},
				goNext(){
					if(this.shopId){
						window.location.replace("add_address.html?token="+this.token+"&unionid="+this.unionid+"&shopId="+this.shopId);
					}else{
						window.location.replace("add_address.html?token="+this.token+"&unionid="+this.unionid);

					}
				}
			}
		});
</script>	
</body>
</html>